home *** CD-ROM | disk | FTP | other *** search
- #include <GestaltEqu.h>
- #include "FMAT.h"
-
- /*
- File ResFMATEd.c
- by Michael Hecht (Michael_Hecht@mac.sas.com)
- July 14, 1993
-
- based on material
- Copyright Apple Computer, Inc. 1985-1990
- All rights reserved.
-
- Some modifications by Erik A. Johnson (johnsone@uxh.cso.uiuc.edu) for
- THINK C (5.0.1).
- */
-
- enum {
- kFMATEditDLOG = 0,
- kFMATEditFormatItem = 1,
- kFMATEditPositiveItem, kFMATEditNegativeItem, kFMATEditZeroItem,
-
- kFMATStatusStr = 0
- };
-
- /* _PStrCopy: Copy a Pascal string */
- void _PStrCopy( ConstStr255Param src, StringPtr dest )
- {
- BlockMove( src, dest, Length( src ) + 1 );
- }
-
- /* _PStrCat: Concatenate two Pascal strings */
- void _PStrCat( ConstStr255Param pend, StringPtr dest )
- {
- BlockMove( pend + 1, dest + Length( dest ) + 1, Length( pend ));
- Length( dest ) += Length( pend );
- }
-
-
- /* ExampleItem: Dialog user item callback to display an example formatted value */
- static pascal void ExampleItem( DialogPtr theDialog, short item )
- {
- Rect iRect;
- FontInfo info;
-
- rFMATHandle myFMAT;
- Handle iHandle;
- StringPtr example;
- long result;
-
- short iType;
- short txFont, txSize;
-
-
- /* Retrieve handle to our FMAT info and lock it down */
- myFMAT = ( rFMATHandle )GetWRefCon( theDialog );
- HLock(( Handle )myFMAT );
-
- /* Determine which string to display */
- switch( item ) {
- case kFMATEditPositiveItem:
- example = ( *myFMAT )->positiveExample;
- break;
-
- case kFMATEditNegativeItem:
- example = ( *myFMAT )->negativeExample;
- break;
-
- case kFMATEditZeroItem:
- example = ( *myFMAT )->zeroExample;
- break;
-
- default:
- goto exit;
- }
-
- /* Erase the item */
- GetDItem( theDialog, item, &iType, &iHandle, &iRect );
- EraseRect( &iRect );
-
- /* Save font/size */
- txFont = theDialog->txFont;
- txSize = theDialog->txSize;
-
- /* Switch to this script's mono-spaced font */
- result = GetScript( Font2Script( txFont ), smScriptMonoFondSize );
- TextFont( HiWord( result ));
- TextSize( LoWord( result ));
-
- /* Use bold red text if the format didn't compile */
- if(( *myFMAT )->curStatus != fFormatOK ) {
- TextFace( bold );
- ForeColor( redColor );
- }
-
- /* Position and draw */
- GetFontInfo( &info );
-
- /* Centered vertically and horizontally within item rectangle */
- MoveTo(( iRect.left + iRect.right - StringWidth( example )) >> 1,
- ( iRect.top + iRect.bottom + info.ascent - info.descent - info.leading ) >> 1 );
- DrawString( example );
-
- /* Restore drawing environment */
- TextFont( txFont );
- TextSize( txSize );
- TextFace( 0 );
- ForeColor( blackColor );
-
- exit:
- /* Unlock FMAT info before returning */
- HUnlock(( Handle )myFMAT );
- }
-
- /* FormatStatusStr: Build text string of FormatStatus error code */
- static void FormatStatusStr( FormatStatus status, StringPtr statusStr )
- {
- Str255 numString;
-
-
- /* Empty string just in case; do nothing if no error */
- statusStr[ 0 ] = 0;
- if( status == fFormatOK )
- return;
-
- /* Read error message from resource */
- GetIndString( statusStr, ResID( kFMATStatusStr ), status );
- if( statusStr[ 0 ] > 0 )
- return;
-
- /* Unknown error--use "<error n>" */
- _PStrCopy( "\p<error ", statusStr );
- NumToString( status, numString );
- _PStrCat( numString, statusStr );
- _PStrCat( "\p>", statusStr );
- }
-
- /* FormatExample: Format a single example */
- static void FormatExample( double x, NumFormatString *myCanonical, NumberPartsPtr partsTable,
- StringPtr outString )
- {
- FormatStatus status;
-
-
- /* The funky cast of x here is to overcome a THINK C 5.0 header file mishap */
- status = FormatX2Str( *( extended80 * )&x, myCanonical, partsTable, outString );
-
- /* If there is a formatting error, get the error message */
- if( status != fFormatOK )
- FormatStatusStr( status, outString );
- }
-
- /* UpdateExamples: Update all examples */
- void UpdateExamples( rFMATHandle myFMAT )
- {
- Rect iRect;
- NumFormatString myCanonical;
- NumberParts partsTable;
- TripleInt positions;
- Str255 inString, outString;
-
- DialogPtr theDialog;
- Ptr p;
- Handle iHandle;
-
- FormatStatus status;
- short i;
- short iType;
-
-
- BubbleUp(( Handle )myFMAT ); /* Move our item up in memory */
- HLock(( Handle )myFMAT ); /* Lock it down */
-
- theDialog = ( DialogPtr )( *myFMAT )->w.wind;
- SetPort( theDialog );
-
- /* Zero the canonical format to avoid uninitialized junk */
- for( i = 0, p = ( Ptr )&myCanonical; i < sizeof( myCanonical ); i++ )
- *p++ = 0;
-
- partsTable = ( *myFMAT )->partsTable;
-
- /* Retrieve editable text */
- GetDItem( theDialog, kFMATEditFormatItem, &iType, &iHandle, &iRect );
- GetIText( iHandle, inString );
-
- /* Convert to a canonical format */
- status = Str2Format( inString, &partsTable, &myCanonical );
-
- /* Save in FMAT info */
- ( *myFMAT )->curFormat = myCanonical;
- ( *myFMAT )->curStatus = status;
-
- /* If editable text couldn't be converted, use an error message */
- if( status != fFormatOK ) {
- errExit:
- FormatStatusStr( status, ( *myFMAT )->positiveExample );
- ( *myFMAT )->negativeExample[ 0 ] = 0;
- ( *myFMAT )->zeroExample[ 0 ] = 0;
- goto exit;
- }
-
- /* FMAT info's curPositions might become invalidated */
- ( *myFMAT )->curPosValid = FALSE;
-
- /* Convert format back to a string */
- if( Format2Str( &myCanonical, &partsTable, outString, positions ) != fFormatOK )
- goto errExit;
-
- /* If it matches the original, remember curPositions and mark them as valid */
- if( EqualString( inString, outString, TRUE, TRUE )) {
- BlockMove(( Ptr )positions, ( Ptr )( *myFMAT )->curPositions, sizeof( positions ));
- ( *myFMAT )->curPosValid = TRUE;
- }
-
- /* Reformat the three examples */
- FormatExample( 1234.56, &myCanonical, &partsTable, ( *myFMAT )->positiveExample );
- FormatExample( -1234.56, &myCanonical, &partsTable, ( *myFMAT )->negativeExample );
- FormatExample( 0. , &myCanonical, &partsTable, ( *myFMAT )->zeroExample );
-
- exit:
- /* Invalidate the example user items */
- for( i = kFMATEditPositiveItem; i <= kFMATEditZeroItem; i++ ) {
- GetDItem( theDialog, i, &iType, &iHandle, &iRect );
- InvalRect( &iRect );
- }
-
- /* Unlock FMAT info */
- HUnlock(( Handle )myFMAT );
- }
-
- /* GetNameAndTitle: Fix up the window name and title for our window. */
- static void GetNameAndTitle( StringPtr windowTitle, StringPtr windowName,
- Handle thing )
- {
- _PStrCopy( RESOURCE_STRING, windowTitle );
- SetETitle( thing, windowTitle );
- _PStrCopy( windowTitle, windowName );
- }
-
- /* SetDialogScript: Fix up the dialog to use the given script */
- static void SetDialogScript( rFMATHandle myFMAT, short scriptNum )
- {
- FontInfo info;
- NumberParts partsTable;
-
- DialogPtr theDialog;
- TEHandle hTE;
- long newFont;
- Itl4Handle itl4;
-
- short txFont, txSize;
-
-
- /* Make the dialog the current port */
- theDialog = ( DialogPtr )( *myFMAT )->w.wind;
- SetPort( theDialog );
-
- /* Retrieve system font/size for this script */
- newFont = GetScript( scriptNum, smScriptSysFond );
- txFont = LoWord( newFont );
- txSize = 0;
-
- /* Select an editText item to initialize the dialog's TE record */
- SelIText( theDialog, kFMATEditFormatItem, 0, 32767 );
-
- /* Change editText item font */
- hTE = (( DialogPeek )theDialog )->textH;
- ( *hTE )->txFont = txFont;
- ( *hTE )->txSize = txSize;
-
- /* Change the dialog's font */
- TextFont( txFont );
- TextSize( txSize );
-
- /* Update TE record's font info */
- GetFontInfo( &info );
- ( *hTE )->lineHeight = info.ascent + info.descent + info.leading;
- ( *hTE )->fontAscent = info.ascent;
-
- /* Get itl4 record */
- itl4 = ( Itl4Handle )GetResource( 'itl4',
- GetScript( Font2Script( txFont ), smScriptToken ));
- if( itl4 ) {
-
- /* Retrieve this script's number parts */
- partsTable = *( NumberPartsPtr )(( char * )*itl4 + ( *itl4 )->defPartsOffset );
- ( *myFMAT )->partsTable = partsTable;
-
- /* Rebuild the number parts palette */
- InitNumberPartsPalette(( *myFMAT )->thePalette, &partsTable, txFont );
- }
-
- /* Ensure that the dialog is the current port before returning! */
- SetPort( theDialog );
- }
-
- /* RevertFormat: Handles the "Revert" command */
- static void RevertFormat( rFMATHandle myFMAT )
- {
- Rect iRect;
- Str255 outString;
- NumberParts partsTable;
-
- DialogPtr theDialog;
- Handle iHandle;
-
- short originalFmtScript;
- short iType;
- short start, end;
-
-
- /* Switch to script originally used by format */
- originalFmtScript = ( *myFMAT )->originalFmtScript;
- SetDialogScript( myFMAT, originalFmtScript );
-
- /* Also switch key script if necessary */
- if(( short )GetEnvirons( smKeyScript ) != originalFmtScript )
- KeyScript( originalFmtScript );
-
- /* Restore editable text in dialog */
- theDialog = ( DialogPtr )( *myFMAT )->w.wind;
- _PStrCopy(( *myFMAT )->originalFmtStr, outString );
- GetDItem( theDialog, kFMATEditFormatItem, &iType, &iHandle, &iRect );
- SetIText( iHandle, outString );
- InvalRect( &iRect );
-
- /* Reset selection to positive portion */
- start = ( *myFMAT )->originalPositions[ fPositive ].start - 1;
- end = start + ( *myFMAT )->originalPositions[ fPositive ].length;
- SelIText( theDialog, kFMATEditFormatItem, start, end );
-
- /* Update all examples to reflect reverted edit text */
- UpdateExamples( myFMAT );
- }
-
- /* EditBirth: Create new Format Editor */
- pascal void EditBirth( Handle theResource, ParentHandle dad )
- {
- Str255 windowTitle, windowName;
- Rect iRect;
- NumberParts partsTable;
- TripleInt positions;
- Str255 outString;
-
- long result;
- FMATHandle thing = ( FMATHandle )theResource;
- rFMATHandle myFMAT;
- WindowPtr theWindow;
- Handle iHandle;
- NumberPartsPaletteHandle thePalette;
-
- short item;
- short iType;
- FormatStatus status;
- short txFont;
-
-
- /* If Script Manager isn't available, just use the hex editor */
- if( Gestalt( gestaltScriptMgrVersion, &result ) != noErr || result < 0x0200 ) {
- /* Don't know how to do this yet! */
- return;
- }
-
- /* Prepare window title and request creation of a new window */
- GetNameAndTitle( windowTitle, windowName, ( Handle )thing );
- theWindow = EditorWindSetup( ResID( kFMATEditDLOG ), noColor, 0, 0,
- windowTitle, windowName, TRUE, ResEdID(), dad );
-
- /* If we got a new window, then start up the editor */
- if( !theWindow )
- return;
-
- /* Get memory for and handle to our instance record */
- myFMAT = ( rFMATHandle )NewHandle( sizeof( rFMATRec ));
- if( !myFMAT )
- goto errExit1;
-
- SetPort( theWindow );
-
- /* Put information about this incarnation of the editor and the window */
- /* it is serving into our record. */
- /* (always passed around in the handle myFMAT). */
-
- _PStrCopy( windowName, ( *myFMAT )->w.name );
- ( *myFMAT )->w.father = dad;
- ( *myFMAT )->w.wind = ( WindowPeek )theWindow;
- ( *myFMAT )->w.rebuild = FALSE;
- ( *myFMAT )->w.resWasntLoaded = !WasItLoaded();
- ( *myFMAT )->w.windowType = editorWindow;
- ( *myFMAT )->w.theResType = RESOURCE_TYPE;
- ( *myFMAT )->w.theResFile = HomeResFile(( Handle )thing );
- ( *myFMAT )->w.codeResID = ResEdID();
- ( *myFMAT )->w.theResToEdit = ( Handle )thing;
-
- /* Let the main program know who is to manage this window by giving it */
- /* both our resource ID number and our instance record handle. */
- SetWRefCon( theWindow, ( long )myFMAT );
-
- /* Set up any menus,views, etc. for this window here. */
-
- for( item = kFMATEditPositiveItem; item <= kFMATEditZeroItem; item++ ) {
- GetDItem( theWindow, item, &iType, &iHandle, &iRect );
- SetDItem( theWindow, item, iType, ( Handle )ExampleItem, &iRect );
- }
-
- thePalette = NewNumberPartsPalette( myFMAT );
- if( !thePalette )
- goto errExit1;
- ( *myFMAT )->thePalette = thePalette;
-
- SetDialogScript( myFMAT, ( short )GetEnvirons( smKeyScript ));
-
- ( *myFMAT )->originalFmtStr[ 0 ] = 0;
- ( *myFMAT )->originalFmtScript = Font2Script( theWindow->txFont );
-
- ( *myFMAT )->positiveExample[ 0 ] = 0;
- ( *myFMAT )->negativeExample[ 0 ] = 0;
- ( *myFMAT )->zeroExample[ 0 ] = 0;
-
- /* All done if the resource doesn't yet exist */
- if( GetHandleSize(( Handle )thing ) == 0 )
- return;
-
- /* Convert the format back into editable text */
- partsTable = ( *myFMAT )->partsTable;
- HLock(( Handle )thing );
- status = Format2Str( *thing, &partsTable, outString, positions );
- HUnlock(( Handle )thing );
-
- /* "Revert" it to initialize our structures */
- if( status == fFormatOK ) {
-
- _PStrCopy( outString, ( *myFMAT )->originalFmtStr );
- BlockMove(( Ptr )positions, ( Ptr )( *myFMAT )->originalPositions,
- sizeof( positions ));
-
- RevertFormat( myFMAT );
- }
-
- return;
-
- errExit2:
- CloseNumberPartsPalette( thePalette );
-
- errExit1:
- CloseWindow( theWindow );
- WindReturn( theWindow );
- }
-
- /* PickBirth: Not used for editors */
- pascal void PickBirth( ResType t, ParentHandle dad )
- {
- #pragma unused (t, dad)
- }
-
- /* DoEvent: The resource editor's event handler */
- pascal void DoEvent( EventRecord *evt, ParentHandle object )
- {
- Point where;
-
- rFMATHandle myFMAT = ( rFMATHandle )object;
- WindowPtr theWindow, saveFrontWindow, whichWindow;
- WindowPeek peek;
- DialogPtr theDialog;
- RgnHandle updateRgn;
- NumberPartsPaletteHandle thePalette;
-
- short item;
- short saveWindowKind;
- short scriptNum;
-
-
- /* Handle event passed to us by main program. Just like a 'real' event */
- /* loop, except… there is no loop and we don't have to handle as much */
- /* because the main program will do all the stuff that doesn't apply to us.*/
-
- theWindow = ( WindowPtr )( *myFMAT )->w.wind;
- thePalette = ( *myFMAT )->thePalette;
-
- /*
- * Since we are a relocatable code resource, our ExampleItem user procs may have
- * moved. If so, reset them before trying to call the Dialog Manager.
- */
- for( item = kFMATEditPositiveItem; item <= kFMATEditZeroItem; item++ ) {
- Rect iRect;
- Handle iHandle;
- short iType;
-
-
- GetDItem( theWindow, item, &iType, &iHandle, &iRect );
- if( iHandle != ( Handle )ExampleItem )
- SetDItem( theWindow, item, iType, ( Handle )ExampleItem, &iRect );
- }
-
- /* Vector palette window events to palette event handler */
- if(( *thePalette )->fw.wind == ( WindowPtr )evt->message ) {
- if( evt->what == updateEvt ) {
- UpdatePalette( thePalette );
- return;
- }
-
- /* Make a palette activation event look like it's for the dialog */
- if( evt->what == activateEvt )
- evt->message = ( long )theWindow;
- }
-
- switch( evt->what ) {
-
- case updateEvt:
- /*
- * Since ResEdit helpfully calls BeginUpdate/EndUpdate for me, IsDialogEvent/
- * DialogSelect get extremely confused about how to update the window. My solution
- * is to make a copy of the visRgn, call EndUpdate, and call InvalRgn on my visRgn
- * copy. Then I call IsDialogEvent/DialogSelect. Afterward, I call BeginUpdate
- * again to make ResEdit happy.
- */
- SetPort( theWindow );
- updateRgn = NewRgn();
- CopyRgn( theWindow->visRgn, updateRgn );
- EndUpdate( theWindow );
- InvalRgn( updateRgn );
- DisposeRgn( updateRgn );
- break;
-
- case keyDown:
- /* Do any key processing here. */
-
- /* Special processing for the tab key */
- if(( evt->message & charCodeMask ) == tabKey ) {
- TEHandle hTE;
- FormatClass c;
- short start, end;
-
-
- /* Totally ignore keypress if current positions aren't valid */
- if( !( *myFMAT )->curPosValid )
- return;
-
- hTE = (( DialogPeek )theWindow )->textH;
-
- /* Find the current position */
- for( c = fPositive; c <= fZero; c++ ) {
-
- start = ( *myFMAT )->curPositions[ c ].start - 1;
- end = start + ( *myFMAT )->curPositions[ c ].length;
- if(( *hTE )->selStart >= start && ( *hTE )->selStart <= end ) {
-
- /* Found! Tab backwards if shift-tab */
- if( evt->modifiers & shiftKey ) {
- if( --c > fZero )
- c = fZero;
- }
-
- /* Otherwise tab forwards */
- else {
- if( ++c > fZero )
- c = fPositive;
- }
-
- /* Move selection */
- start = ( *myFMAT )->curPositions[ c ].start - 1;
- end = start + ( *myFMAT )->curPositions[ c ].length;
- SelIText( theWindow, kFMATEditFormatItem, start, end );
- break;
- }
- }
-
- return;
- }
- break;
-
- case mouseDown:
- /* Vector mouse clicks in palette to palette event handler */
- if( FindWindow( evt->where, &whichWindow ) == inContent &&
- ( *thePalette )->fw.wind == whichWindow ) {
- ClickPalette( evt, thePalette );
- return;
- }
- break;
-
- case nullEvent:
- /* Has the keyboard script changed? */
- scriptNum = ( short )GetEnvirons( smKeyScript );
- if( Font2Script( theWindow->txFont ) != scriptNum ) {
-
- /* Switch dialog's script to match */
- SetDialogScript( myFMAT, scriptNum );
-
- /* Convert the current format back into editable text using new script */
- if(( *myFMAT )->curStatus == fFormatOK ) {
- TripleInt positions;
- Str255 outString;
-
- FormatStatus status;
-
-
- HLock(( Handle )myFMAT );
- status = Format2Str( &( *myFMAT )->curFormat,
- &( *myFMAT )->partsTable, outString, positions );
- HUnlock(( Handle )myFMAT );
-
- if( status == fFormatOK ) {
- Rect iRect;
-
- Handle iHandle;
-
- short iType, start, end;
-
-
- /* Remember new positions */
- BlockMove(( Ptr )positions, ( Ptr )( *myFMAT )->curPositions,
- sizeof( positions ));
- ( *myFMAT )->curPosValid = TRUE;
-
- /* Editable text needs to be updated */
- GetDItem( theWindow, kFMATEditFormatItem, &iType, &iHandle, &iRect );
- SetIText( iHandle, outString );
- InvalRect( &iRect );
-
- /* Set selection to positive portion */
- start = positions[ fPositive ].start - 1;
- end = start + positions[ fPositive ].length;
- SelIText( theWindow, kFMATEditFormatItem, start, end );
- }
- }
-
- UpdateExamples( myFMAT );
- }
- break;
- }
-
- /*
- * Since this is a modeless dialog, I am calling IsDialogEvent/DialogSelect to
- * handle events. To make this work, I have to temporarily change the windowKind
- * field of my window to dialogKind.
- */
- peek = ( WindowPeek )theWindow;
- saveWindowKind = peek->windowKind;
- peek->windowKind = dialogKind;
-
- /*
- * Since I have a floating palette, it is always frontmost. This makes
- * IsDialogEvent return FALSE for null, activate, mouseDown, and keyDown events.
- * My solution is to blast my dialog’s pointer into the low memory global
- * WindowList before calling IsDialogEvent/DialogSelect, and restore WindowList
- * afterwards. I tried using BringToFront, but when the palette overlapped the
- * dialog, they were constantly swapping places.
- */
- saveFrontWindow = ( WindowPtr )WindowList;
- if( saveFrontWindow == ( *thePalette )->fw.wind )
- WindowList = peek;
- else
- saveFrontWindow = 0;
-
- /* Process the event */
- if( IsDialogEvent( evt ))
- DialogSelect( evt, &theDialog, &item );
-
- /* Restore WindowList */
- if( saveFrontWindow )
- WindowList = ( WindowPeek )saveFrontWindow;
-
- /* Restore windowKind */
- peek->windowKind = saveWindowKind;
-
- /* Event post-processing */
- switch( evt->what ) {
- case updateEvt:
- /* Call BeginUpdate to balance the EndUpdate that ResEdit will call for us */
- BeginUpdate( theWindow );
- break;
-
- case keyDown:
- /* Update the examples after every key press */
- UpdateExamples( myFMAT );
- break;
- }
- }
-
- /* DoInfoUpdate: Handles the "Get Resource Info" command */
- pascal void DoInfoUpdate( short oldID, short newID, ParentHandle object )
- {
- rFMATHandle myFMAT = ( rFMATHandle )object;
- ParentHandle father = ( *myFMAT )->w.father;
- Str255 windowTitle, windowName;
-
-
- HLock(( Handle )myFMAT );
-
- /* Since our ID has changed, we need to change our window title */
- GetNameAndTitle( windowTitle, windowName, ( *myFMAT )->w.theResToEdit );
- GetWindowTitle( windowTitle, windowName, TRUE, father );
-
- /* Save the new name in my data structure. */
- _PStrCopy( windowName, ( *myFMAT )->w.name );
-
- /* Set the new window title. */
- SetWTitle(( WindowPtr )( *myFMAT )->w.wind, windowTitle );
-
- /* Now, let our father object know that our ID has been changed */
- ( *father )->rebuild = TRUE; /* Rebuild the picker list. */
- CallInfoUpdate( oldID, newID, ( long )father, ( *father )->wind->windowKind );
-
- HUnlock(( Handle )myFMAT );
- }
-
- /* IsThisYours: Is this your resource? */
- pascal Boolean IsThisYours( Handle thing, ParentHandle object )
- {
- return thing == ( *object )->theResToEdit;
- }
-
- /* FormatChanged: Determine if the format has been significantly changed by editing */
- static Boolean FormatChanged( rFMATHandle myFMAT )
- {
- Rect iRect;
- Str255 inString;
-
- Handle iHandle;
-
- short iType;
-
-
- /* Get current editable text */
- GetDItem(( DialogPtr )( *myFMAT )->w.wind, kFMATEditFormatItem, &iType, &iHandle, &iRect );
- GetIText( iHandle, inString );
-
- /* Is it what we started with? */
- return !EqualString( inString, ( *myFMAT )->originalFmtStr, TRUE, TRUE );
- }
-
- /* Close down the window and get rid of any memory that has been allocated. */
- /* Returns TRUE if the operation was successful. If notRevert is FALSE the */
- /* resource isn't released and the data handle isn't disposed (though all the */
- /* handles it contains are disposed). */
- static Boolean DoClose( Boolean notRevert, rFMATHandle myFMAT )
- {
- Boolean changed;
- FMATHandle hFMAT;
-
-
- /* Let parent try to close; cancel if parent aborted */
- PassMenu( fileMenu, closeItem, ( ParentHandle )myFMAT );
- if( WasAborted())
- return FALSE;
-
- /* If the resource was edited, mark it as changed */
- changed = FALSE;
- hFMAT = ( FMATHandle )( *myFMAT )->w.theResToEdit;
- if( !CloseNoSave() && FormatChanged( myFMAT )) {
-
- /* Disallow close if format won't compile */
- if(( *myFMAT )->curStatus != fFormatOK ) {
- SysBeep( 1 );
- Abort();
- return FALSE;
- }
-
- PtrToXHand(( Ptr )&( *myFMAT )->curFormat, ( Handle )hFMAT,
- ( *myFMAT )->curFormat.fLength + 1 );
- ChangedResource(( Handle )hFMAT );
- changed = TRUE;
- }
-
- /* Close it down */
- CloseDialog(( DialogPtr )( *myFMAT )->w.wind );
- WindReturn(( WindowPtr )( *myFMAT )->w.wind ); /*Mark window record as being available */
- SetTheCursor( arrowCursor ); /* Make sure the cursor is arrow cursor */
-
- /* Delete any menus that we added and redraw the menu bar. */
- /* Be sure to dispose of any handles you are done with. */
- /* Release the resource if we were launched from a picker. */
- if( !changed && notRevert && ( *myFMAT )->w.resWasntLoaded &&
- ( *( *myFMAT )->w.father )->windowType != editorWindow ) {
- ReleaseResource(( Handle )hFMAT );
- /* Let it be free (if it is not changed)! */
- }
-
- CloseNumberPartsPalette(( *myFMAT )->thePalette );
-
- if( notRevert )
- DisposHandle(( Handle )myFMAT );
-
- return TRUE;
- }
-
- /* DoMenu: Handle menu commands */
- pascal void DoMenu( short menu, short item, ParentHandle object )
- {
- rFMATHandle myFMAT = ( rFMATHandle )object;
- Handle theResource;
- DialogPtr theDialog;
-
-
- BubbleUp(( Handle )myFMAT );
- HLock(( Handle )myFMAT );
- theDialog = ( DialogPtr )( *myFMAT )->w.wind;
- SetPort( theDialog ); /* Set the port to our window */
-
- theResource = ( *myFMAT )->w.theResToEdit;
-
- /* Again, we handle the menu stuff just as we would in a 'real' application*/
- /* except that we only have to handle those items that apply to our editor.*/
-
- switch( menu ) {
- case fileMenu:
-
- switch( item ) {
- case closeItem: /* Close our window */
-
- if( DoClose( TRUE, myFMAT )) {
- return; /* Return immediately since our resource is gone! */
- }
- break;
-
- case saveItem: /* Pass the save on to other windows */
- PassMenu( fileMenu, saveItem, ( ParentHandle )myFMAT );
- break;
-
- case printItem:
- /* Cheesy default printing */
- PrintWindow( 0 );
- break;
- }
- break;
-
- case rsrcMenu:
-
- switch( item ) {
-
- case rsrcRevertItem:
- if( !FormatChanged( myFMAT ))
- break;
-
- if(( *myFMAT )->originalFmtStr[ 0 ] == 0 ) {
-
- /* The resource was newly added so we need to remove it */
-
- /* Make sure that the picker list is rebuilt to remove this item */
- ( *( *myFMAT )->w.father )->rebuild = TRUE;
-
- /* Close the window */
- if( DoClose( FALSE, myFMAT )) {
- RERemoveAnyResource(( *myFMAT )->w.theResFile, theResource );
-
- /* Dispose the resource itself */
- DisposHandle(( Handle )myFMAT );
- return; /* Since the resource is gone. */
- }
- }
-
- RevertFormat( myFMAT );
- break;
-
- case rsrcGetInfoItem: /* Show GetInfo window */
- ShowInfo( theResource, ( ParentHandle )myFMAT );
- break;
- }
- break;
-
- case editMenu: /* Implement the edit menu here */
- switch( item ) {
- case cutItem:
- DlgCut( theDialog );
- break;
- case copyItem:
- DlgCopy( theDialog );
- break;
- case pasteItem:
- DlgPaste( theDialog );
- break;
- case clearItem:
- DlgDelete( theDialog );
- break;
- }
- break;
- }
-
- HUnlock(( Handle )myFMAT );
- }
-